#ifndef _TAD_H_
#define _TAD_H_

#include "defines.h"

struct peer_list {
  char key[IPPORT_LENGTH + 1];
  struct peer_list *next;
};

struct file_list {
  char key[HASH_LENGTH + 1];
  struct file_list *next;
};

struct file {
  char key[HASH_LENGTH + 1];
  char name[MAX_NAME];
  long file_size;
  int piece_size;
  char buffermap[MAX_BMSIZE];
  struct peer_list *peers;
  struct file *next;
};

struct peer {
  char key[IPPORT_LENGTH + 1];
  char ip[IP_LENGTH + 1];
  char port[PORT_LENGTH + 1];
  struct file_list *leeched_files;
  struct file_list *seeded_files;
  int thread_id;
  int fd;
  struct peer *next;
};


void add_peer(struct peer *p);
struct peer *find_peer(char *key);
struct file *add_file(struct file *p, struct file *hashmap_files);
struct file *find_file(char *key, struct file *hashmap_files);
struct file *find_file_subname(char *subname, struct file *hashmap_files);

void erase(char *buff, int n);
char* goto_next_word(char *string, char *cpy[BUF_SIZE]);

#endif











